import aiofiles
from WebBackend.utils import mylog


async def read_file_async(filepath: str, return_type: str = 'list') -> str | list[str]:
    mylog.info(f'[#3b1c]Reading file:{filepath}  ')
    stream = await aiofiles.open(filepath, 'r')
    if return_type == 'list':
        return await stream.readlines()
    else:
        return await stream.read()


def read_file_sync(filepath: str, return_type: str = 'list') -> str | list[str]:
    mylog.info(f'[#3d01]Reading file:{filepath}')
    with open(filepath, 'r') as f:
        if return_type == 'list':
            return f.readlines()
        else:
            return f.read()
